package com.family.pedigree.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.family.pedigree.domain.FamilyUserInfo;
import com.family.pedigree.domain.common.FamilyMan;
import com.family.pedigree.mapper.FamilyUserInfoMapper;
import com.family.pedigree.service.IFamilyUserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 个人信息表 服务实现类
 * </p>
 *
 * @author forever
 * @since 2025-01-16
 */
@Service
public class FamilyUserInfoServiceImpl extends ServiceImpl<FamilyUserInfoMapper, FamilyUserInfo> implements IFamilyUserInfoService {

    @Override
    public void add(FamilyUserInfo familyUserInfo) {
        save(familyUserInfo.setCreateBy("admin").setUpdateBy("admin"));
    }

    @Override
    public List<FamilyUserInfo> selectPage(FamilyUserInfo familyUserInfo) {
        return list(Wrappers.<FamilyUserInfo>lambdaQuery()
                .like(StringUtils.isNotBlank(familyUserInfo.getName()), FamilyUserInfo::getName, familyUserInfo.getName())
                .like(StringUtils.isNotBlank(familyUserInfo.getFormerName()), FamilyUserInfo::getFormerName, familyUserInfo.getFormerName())
                .like(StringUtils.isNotBlank(familyUserInfo.getPoliticsFace()), FamilyUserInfo::getPoliticsFace, familyUserInfo.getPoliticsFace())
                .like(StringUtils.isNotBlank(familyUserInfo.getWxNumber()), FamilyUserInfo::getWxNumber, familyUserInfo.getWxNumber())
                .like(StringUtils.isNotBlank(familyUserInfo.getEmail()), FamilyUserInfo::getEmail, familyUserInfo.getEmail())
                .like(StringUtils.isNotBlank(familyUserInfo.getPhone()), FamilyUserInfo::getPhone, familyUserInfo.getPhone())
                .like(StringUtils.isNotBlank(familyUserInfo.getCollage()), FamilyUserInfo::getCollage, familyUserInfo.getCollage())
                .like(StringUtils.isNotBlank(familyUserInfo.getMajor()), FamilyUserInfo::getMajor, familyUserInfo.getMajor())
                .eq(familyUserInfo.getGender() != null, FamilyUserInfo::getGender, familyUserInfo.getGender())
                .eq(familyUserInfo.getIsDeath() != null, FamilyUserInfo::getIsDeath, familyUserInfo.getIsDeath())
                .orderByDesc(FamilyUserInfo::getCreateTime));
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void delById(Long infoId) {
        removeById(infoId);
    }

    @Override
    public List<FamilyMan> findManTotal() {
//        return baseMapper.findManTotal();
        return null;
    }
}
